var TowerC = Tower.extend({
    ///////////////////////////////////////////////////////////
    ctor : function( filename,towerData ){//series,power,speed,fireRange,fireTime,bulletRes
        this._super(filename,towerData);
    },
    onEnter:function () {
        this._super();
    },
    onExit : function(){
        this._super();
    },
    //////////////////////////////////////////////////////////////////////
    dispatcher:function(){
        return "b2.png";
    },
    newBullet : function(direct,distance){
        cc.log("new bullet");
        var name = MainResource(this.dispatcher()); // "res/"+this._bulletRes;
        var newBullet = new BulletC( name,this._power,this._speed,this._bulletType );
        newBullet.setPosition(this.getPosition());
        newBullet.setSpeedScale(direct,distance);

        // set bullet size
        this.addBullet(newBullet);
    },
    reviveBullet : function(bullet,direct,distance){
        bullet.setPosition(this.getPosition());
        bullet.setSpeedScale(direct,distance);
        // set bullet size
        bullet.setPower(this._power);
        bullet.setSpeed(this._speed);
        bullet.revive();
    },
    fighting : function(direct){
        if ( this._canFire ){
            var distance = cc.pDistance(this.getPosition(),direct );
            if ( distance<this._fireRange ){
                cc.log("distance: "+distance);
                var that = this;
                this._canFire = false;
                var bullet = this.getBulletFromBuffer();
                if ( bullet ){
                    this.reviveBullet(bullet,direct,distance);
                }else{
                    this.newBullet(direct,distance);
                }
                this.runAction( cc.Sequence.create(
                    new cc.DelayTime( this._fireTime ),
                    new cc.CallFunc( function(){ that._canFire = true;cc.log("open fire trigger");} )
                ));
                var filename = AudioResource("fish.mp3");
                cc.audioEngine.playEffect(filename);
                return true;
            }
        }
        return false;
    }
});
////////////////////////////////////////////////////////////////
TowerC.create = function (filename,towerData ) {
    var tower = new TowerC(filename,towerData );
    return tower;
};
